<?php
include_once("./Db_pdo.class.php");
require('./sql/s.php');//引入类
// $DB=new Db_pdo("jmshop","root","root");
// $DB=new Db_pdo("cxh_v3_test","cxhv3","cxhv3pwd!@#");
$DB=new Db_pdo("cxh_v3","cxhv3","cxhv3pwd!@#");
echo '<pre>'; 
//计算 
// $p = new \digui();




// // //会员销售排名
// $sql = "SELECT

// b.uex_parentID,
// b.uex_parentAccount,
// b.member_id,
// b.uex_level
// FROM
// 	ims_ewei_shop_member as a
// INNER JOIN ims_cxh_user_ex as b
// on a.id = b.member_id
// WHERE
// 	a.createtime > 1514736048
// and uex_level >1";
// $cxhusers = $DB->new_query($sql);
// $cxhusers = $cxhusers->fetchAll(PDO::FETCH_ASSOC);  
// echo '<pre>';

// foreach ($cxhusers as $key => $value) {
// 	if($value['uex_level']==2){
// 		$cxhusers[$key]['money'] = 3000;
// 	}else if($value['uex_level']==3){
// 			$cxhusers[$key]['money'] = 20000;
// 	}


// }


// $newarr =array();
// foreach ($cxhusers as $key => $value) {
// 	if(!empty($newarr[$value['uex_parentID']])){
// 		$newarr[$value['uex_parentID']]['count'] += 1;
// 		$newarr[$value['uex_parentID']]['money'] +=$value['money']; 
// 	}else{
// 		$newarr[$value['uex_parentID']] = $value;
// 		$newarr[$value['uex_parentID']]['count'] = 1;
// 	}

// 	// print_r($value);
// }
//  print_r($newarr);
// $arrs = $p->sortArray($newarr,'money',SORT_DESC);
// print_r($arrs);



// // //1541001600

//各大区情况
// $sql = "SELECT 
// 	b.id,
// 	b.realname,
// 	a.price,
// c.uex_parentList
// FROM
// 	ims_ewei_shop_order AS a
// INNER JOIN ims_ewei_shop_member AS b ON b.openid = a.openid
// INNER JOIN ims_cxh_user_ex AS c ON b.id = c.member_id
// WHERE
// 	a.paytime >= 1543593616
// 	and a.paytime <=1546271956
// AND isupgrade = 1";



// $cxhusers = $DB->new_query($sql);
// $cxhusers = $cxhusers->fetchAll(PDO::FETCH_ASSOC); 
//  //print_r($cxhusers);
// foreach ($cxhusers as $key => $value) {
// 	$s = explode(',',$value['uex_parentList']);

// 	if($s['1']==1){
// 		$sqls = "SELECT
// 					uex_provinceName
// 				FROM
// 					ims_cxh_user_ex
// 				WHERE member_id =".$s['2'];
// 		$user = $DB->new_query($sqls);
// 	}else{
// 		$sqls = "SELECT
// 					uex_provinceName
// 				FROM
// 					ims_cxh_user_ex
// 				WHERE member_id =".$s['1'];
// 		$user = $DB->new_query($sqls);
// 	}

// 	$user = $user->fetchAll(PDO::FETCH_ASSOC); 
// 	if($user['0']['uex_provinceName']){
// 		$cxhusers[$key]['p'] = $user['0']['uex_provinceName'];

// 		$newarrs[] = $cxhusers[$key];
// 	}else{
// 		$sqles = "SELECT
//  					uex_provinceName
//  				FROM
// 					ims_cxh_user_ex
//  				WHERE member_id =".$s['3'];
// 		$useres = $DB->new_query($sqles);
// 		$useres = $useres->fetchAll(PDO::FETCH_ASSOC);

// 		if($useres['0']['uex_provinceName']){
// 			$cxhusers[$key]['p'] = $useres['0']['uex_provinceName'];
// 			$newarrs[] = $cxhusers[$key];
// 		}else{
// 			$newarr[] = $cxhusers[$key];
// 		}
		
// 	}
	
// }

// print_r($newarr);
// echo '<br>';
// print_r($newarrs);
// exit;
// // //存放未查到的
//file_put_contents('nouser.txt',serialize($newarr));
//file_put_contents('users.txt',serialize($newarrs));



// $new =  unserialize(file_get_contents('users.txt')); 
// $arr1 = array('四川省','云南省','内蒙古自治区','江苏省','浙江省','江西省');
// $arr2 = array('新疆区','甘肃省','陕西省','贵州省','河南省','河北省');
// $arr3 = array('广东省','海南省','福建省','广西省');
// $arr4 = array('重庆市','湖北省','湖南省','山东省','吉林省');

// $count1 = $count2 = $count3 =$count4 = 0;
// foreach ($new as $key => $value) {
// 	// print_r($value['p']);
// 	if(in_array($value['p'],$arr1)){
		
// 		$count1+=$value['price'];
// 	}else if(in_array($value['p'],$arr2)){
		
// 		$count2+=$value['price'];
// 	}else if(in_array($value['p'],$arr3)){
		
// 		$count3+=$value['price'];
// 	}else if(in_array($value['p'],$arr4)){
		
// 		$count4+=$value['price'];
// 	}
// }

// echo $count1;
// echo '<br>';
// echo $count2;
// echo '<br>';
// echo $count3;
// echo '<br>';
// echo $count4;
// echo '<br>';
// // print_r($new);
// $nonew =  unserialize(file_get_contents('nouser.txt')); 
// // print_r($nonew);

// foreach ($nonew as $key => $value) {
// 	$s = explode(',',$value['uex_parentList']);
// 	$sqls = "SELECT
//  					uex_provinceName
//  				FROM
// 					ims_cxh_user_ex
//  				WHERE member_id =".$s['4'];
// 	$user = $DB->new_query($sqls);
// 	$user = $user->fetchAll(PDO::FETCH_ASSOC); 
// 	$nonew[$key]['p'] = $user['0']['uex_provinceName'];
// }
// print_r($nonew);
//这里开始结束导入

// $new = unserialize(file_get_contents('users.txt')); 

// $arr = array_chunk($new, 20000);

// foreach($arr as $v) {
// 	$sql = "INSERT INTO ceshi (`name`,`money`,`area`) VALUES ";
// 	foreach ($v as $value) { 
// 		$param['name'] = $value['realname'];
// 		$param['money'] =$value['price'];
// 		$param['area'] = $value['p'];
// 	    $values="('".implode("','",array_values($param))."'),";
// 	    // echo $values;
// 	    $sql .= $values;
// 	}
// 	$sql = rtrim($sql, ",");
// 	echo $sql;
// 	//$DB->db->query($sql);
// 	// return ;
// }

// $nonew = unserialize(file_get_contents('nouser.txt')); 
// print_r($nonew);




?>

